﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using WindowsFormsApplication1.DTO;

namespace WindowsFormsApplication1
{
    class GiaoVienDAO
    {
        public static List<GiaoVienDTO> GetList()
        {
            SqlConnection ketNoi = AbstractDAO.Connection();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = ketNoi;
            cmd.CommandText = @"SELECT * FROM GIAOVIEN";

            // Thực thi câu lệnh 
            List<GiaoVienDTO> ds = new List<GiaoVienDTO>();
            SqlDataReader boDoc = cmd.ExecuteReader();
            while (boDoc.Read())
            {
                GiaoVienDTO gv = new GiaoVienDTO();
                gv.maGiaoVien = boDoc.GetString(0);
                gv.tenGiaoVien = boDoc.GetString(1);
                gv.maDonVi = boDoc.GetInt32(2);
                ds.Add(gv);
            }
            boDoc.Close();
            return ds;
        }

        public static int GetMaLoaiGiaoVien(string maGiaoVien)
        {
            SqlConnection ketNoi = AbstractDAO.Connection();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = ketNoi;
            cmd.CommandText = @"select LoaiGiaoVien from GIAOVIEN where MaGiaoVien = '"+maGiaoVien+"'";

            SqlDataReader boDoc = cmd.ExecuteReader();
            while (boDoc.Read())
            {
                return boDoc.GetInt32(0);
            }
            return -1;
        }
    }
}
